@echo off
call:genProto user
call:genProto goods 1
call:genProto inventory 1
call:genProto order 1
call:genProto consul
call:genProto userop

goto genProto_end

:genProto
SETLOCAL

set DOMAIN=%1
set GATEWAY=%2
set PROTO_PATH=.\%DOMAIN%_srv\proto
set GO_OUT_PATH=.\%DOMAIN%_srv\proto\gen\v1

IF NOT EXIST %GO_OUT_PATH% (
    mkdir %GO_OUT_PATH%
)
protoc -I=%PROTO_PATH% --go_out=paths=source_relative:%GO_OUT_PATH% --go_opt=paths=source_relative --go-grpc_out=paths=source_relative:%GO_OUT_PATH% --go-grpc_opt=paths=source_relative %DOMAIN%.proto

if not defined GATEWAY (
	goto :eof
)
protoc -I=%PROTO_PATH% --grpc-gateway_out=paths=source_relative:%GO_OUT_PATH% --grpc-gateway_opt paths=source_relative --grpc-gateway_opt grpc_api_configuration=%PROTO_PATH%\%DOMAIN%.yaml %DOMAIN%.proto

ENDLOCAL
:genProto_end